package com.loop.netty.inboundandoutbound;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * netty 自定义的通道初始化类
 * @author zhangxiaolu
 * @since 2023-09-22 22:52
 */
public class MyServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 获取 pipeline
        ChannelPipeline pipeline = ch.pipeline();
        // 先加入相关的handler
        // 入站的handler 进行解码，自定义一个，用来处理业务逻辑
        pipeline.addLast(new MyByteToLongDecoder2())
                .addLast(new MyLongToByteEncoder())// 出栈的编码器
                .addLast(new MyServerHandler());

    }
}
